export const loginPage = {
	async onShow() {
		await this.login2()
		this.getUserInfo2()
	},
	created() {

	},
	methods: {
		getUserInfo2(){
			if (uni.getStorageSync('userInfo')) {
				this.$req.post('/shanghu/userInfo', {
					uid: uni.getStorageSync('uid')
				}).then(res => {
					let data = res.data.data
					uni.removeStorageSync('userInfo')
					uni.setStorageSync('userInfo',data)
				})
				
			}
		},
		async login2() {
			const info = wx.getSystemInfoSync()
			let handy = 1
			if (info.system.indexOf('Android') > -1) {
				handy = 1
			} else {
				handy = 2
			}
			if (uni.getStorageSync('userInfo')) {

				return
			}
			uni.showLoading({
				title: '正在登录'
			})
			await uni.login({
				provider: 'weixin',
				success: (res) => {
					this.$req.post('/shanghu/userlogin', {
						code: res.code,
						handy
						// pid: ''
					}).then(res => {
						uni.setStorageSync('uid', res.data.data.id)
						uni.setStorageSync('userInfo', res.data.data)
						uni.hideLoading()
						this.reload()
						// this.phoneshow = true
					})
				},
				fail: (err) => {
					console.log('登录失败', err)
				}
			})
		},
		reload() {
			// 页面重载
			const pages = getCurrentPages()
			// 声明一个pages使用getCurrentPages方法
			const curPage = pages[pages.length - 1]
			// 声明一个当前页面
			curPage.onLoad(curPage.options) // 传入参数
			curPage.onShow()
			curPage.onReady()
			// 执行刷新
		},
	}

}